package cn.ssm.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 * @author 黄少涛
 *
 */
public class DateUtil {
	
	// 将日期格式的字符串转换为长整型
	public static long Date2Long(String date) {
			long num = 0L;
		  try {
			   String format = "yyyy-MM-dd HH:mm:ss";
			    SimpleDateFormat sf = new SimpleDateFormat(format);
			    num = sf.parse(date).getTime();
			   
			  } catch (ParseException e) {
			   e.printStackTrace();
			  }
		  	return num;
	}
	
	//将长整型数字转换为日期格式的字符串
	public static String Long2Date(long time) {
		if(time>0) {
			  String  format = "yyyy-MM-dd HH:mm:ss";
			  SimpleDateFormat sf = new SimpleDateFormat(format);
			  Date date = new Date(time);
			  return sf.format(date);

		}else {
			return "";
		}
		
	}
	

}
